package com.tencent.iov.cowin.befsale.clue.controller.cus;

import com.tencent.iov.cowin.befsale.clue.controller.cus.assembler.OemCustomerAssembler;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.*;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.response.CustomerResponse;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.response.OemCustomerResponse;
import com.tencent.iov.cowin.befsale.clue.domain.cus.po.OemCustomer;
import com.tencent.iov.cowin.befsale.clue.service.cus.OemCustomerService;
import com.software.boot.common.entity.Response;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import com.software.common.config.SearchLocalHeader;
import com.software.common.enums.SCRMRequestHeaderEnum;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Describe: 总部客户表主表+客户好友关联表_Controller层
 * @author: xiamu
 * @created: 2021-12-21 18:37:29
 * @version: 1.0
 */
@RestController
@RequestMapping(value = "/v1/demo/oemCustomer", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "总部客户表主表+客户好友关联表_Controller层")
public class OemCustomerController {

    @Autowired
    private OemCustomerService oemCustomerService;

    /**
     * 通过ID获取详细信息
     *
     * @param: id
     * @return: OemCustomer对象
     */
    @ApiOperation(value = "OemCustomer管理-通过ID获取详细信息接口", httpMethod = "GET", response = Response.class, notes = "get_detail_by_id")
    @RequestMapping(path = "/get_detail_by_id", method = RequestMethod.GET)
    public Response<CustomerResponse> getDetailById(@ApiParam(required = true, value = "对象ID", defaultValue = "1") @RequestParam("id") Long id) {
        return Response.success(oemCustomerService.getDetailById(id));
    }

    /**
     * 单条数据插入OemCustomer
     *
     * @param request
     * @return 插入的条数
     */
    @ApiOperation(value = "OemCustomer管理-添加信息接口", httpMethod = "POST", response = Response.class, notes = "add")
    @RequestMapping(path = "/add", method = RequestMethod.POST)
    public Response<Integer> add(@Valid @RequestBody AddOemCustomerRequest request) {
        return Response.success(oemCustomerService.insert(OemCustomerAssembler.transformVOToPO(request, OemCustomer.class)));
    }

    /**
     * 批量插入OemCustomer
     *
     * @param requests
     * @return 批量插入的条数
     */
    @ApiOperation(value = "OemCustomer管理-批量插入OemCustomer接口", httpMethod = "POST", response = Response.class, notes = "add_batch")
    @RequestMapping(path = "/add_batch", method = RequestMethod.POST)
    public Response<Integer> addBatch(@Valid @RequestBody List<QueryOemCustomerRequest> requests) {
        return Response.success(oemCustomerService.insertBatch(OemCustomerAssembler.transformPOToResponseVoList(requests, OemCustomer.class)));
    }

    /**
     * 通过ID修改信息接口
     *
     * @param: request
     * @return: 修改的条数
     */
    @ApiOperation(value = "OemCustomer管理-修改信息接口", httpMethod = "POST", response = Response.class, notes = "update")
    @RequestMapping(path = "/update", method = RequestMethod.POST)
    public Response<Integer> update(@Valid @RequestBody UpdateCustomerRequest request) {
        return Response.success(oemCustomerService.update(request));
    }

    /**
     * 通过ID删除数据
     *
     * @param request
     * @return 删除的条数
     */
    @ApiOperation(value = "OemCustomer管理-通过ID删除接口", httpMethod = "POST", response = Response.class, notes = "delete")
    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    public Response<Integer> delete(@Valid @RequestBody DeleteOemCustomerRequest request) {
        return Response.success(oemCustomerService.delete(OemCustomerAssembler.transformVOToPO(request, OemCustomer.class)));
    }

    /**
     * 根据条件查询对象list列表
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "OemCustomer管理-根据条件查询对象list列表接口", httpMethod = "POST", response = Response.class, notes = "query_list_by_param")
    @RequestMapping(path = "/get_list_by_param", method = RequestMethod.POST)
    public Response<List<CustomerResponse>> getListByParam(@RequestBody QueryCustomerRequest request) {
        return Response.success(oemCustomerService.getListByParam(request));
    }

    /**
     * 根据条件查询对象Page记录
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "OemCustomer管理-根据条件查询对象Page记录接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
    @RequestMapping(value = "/get_page_by_param", method = RequestMethod.POST)
    public Response<PageResponse<OemCustomerResponse>> getPageByParam(@RequestBody PageRequest<QueryOemCustomerRequest> request) {
        PageResponse<OemCustomer> oemCustomerPageResponse = oemCustomerService.getPageByParam(OemCustomerAssembler.transformVOToPOPage(request, OemCustomer.class));
        return Response.success(OemCustomerAssembler.transformPOToResponseVoPage(oemCustomerPageResponse, OemCustomerResponse.class));
    }

    /**
     * 根据条件查询单个对象
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "OemCustomer管理-根据条件查询单个对象接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
    @RequestMapping(value = "/get_one_by_param", method = RequestMethod.POST)
    public Response<OemCustomerResponse> getOneByParam(@RequestBody QueryOemCustomerRequest request) {
        CustomerResponse oemCustomer = oemCustomerService.getOneByParam(OemCustomerAssembler.transformVOToPO(request, OemCustomer.class));
        return Response.success(OemCustomerAssembler.transformPOToResponseVo(oemCustomer, OemCustomerResponse.class));
    }


    /**
     * 验证客户是否存在活跃线索，若存在则不能创建线索
     * @param: id
     * @return: OemCustomer对象
     */
    @ApiOperation(value = "OemCustomer管理-验证客户是否存在活跃线索，若存在则不能创建线索", httpMethod = "GET", response = Response.class, notes = "checkCustomerPhone")
    @RequestMapping(path = "/checkCustomerPhone", method = RequestMethod.GET)
    public Response<Boolean> checkCustomerPhone(@ApiParam(required = true, value = "手机号") @RequestParam("phone") String phone){
         String dealerId = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_DEALER_ID.getCode());
         String tenantId = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_TENANTID.getCode());
         String corpId = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_CORP_ACCOUNTID.getCode());

         Boolean falg=oemCustomerService.checkCustomerPhone(phone,dealerId,tenantId,corpId);
         return Response.success(falg);
    }
}